package kr.saeildamil.androidstudy.ch14;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class NumEditWidjet extends LinearLayout implements TextWatcher {
	EditText mEditText;
	TextView mTextView;

	public NumEditWidjet(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public NumEditWidjet(Context context) {
		super(context);
		init();
	}

	private void init() {
		setOrientation(LinearLayout.VERTICAL);
		mEditText = new EditText(getContext());
		mTextView = new TextView(getContext());
		mTextView.setText("Now Length :  0 Characters");

		LinearLayout.LayoutParams params = new LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.WRAP_CONTENT);
		addView(mEditText, params);
		addView(mTextView, params);

		mEditText.addTextChangedListener(this);
	}

	public void onTextChanged(CharSequence s, int start, int before, int count3) {
		mTextView.setText("Now Length : " + s.length() + "Characters");
	}

	public void beforeTextChanged(CharSequence s, int start, int before,
			int count) {

	}

	public void afterTextChanged(Editable s) {

	}

}
